<?php
/**
 * 图片采集器
 *
 * @Author: yuanji <fenglangyj@139.com>
 * @DateTime: 12-11-3 下午1:44
 * @Copyright (c) 2012 http://www.magentoui.com All rights reserved.
 * @Version  $Id: sss.php,v 1.0 uw Exp $
 * @Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
 */
class GatherAdminAction extends CommonAction{
	public function index(){
		$url = "https://ajax.googleapis.com/ajax/services/search/images?"."v=1.0&q=site:www.mmonly.com";
		
		$url = "http://www.google.com.hk/url?sa=p&hl=zh-CN&pref=hkredirect&pval=yes&q=http://www.google.com.hk/search%3Fq%3Dsite:www.wallba.com%26hl%3Dzh-CN%26newwindow%3D1%26safe%3Dstrict%26biw%3D1440%26bih%3D544%26gbv%3D2%26tbm%3Disch%26ijn%3D2%26ei%3DUmB9T6KEOLCtiQfs_eXBCQ%26sprg%3D6%26page%3D7%26start%3D85&ust=1333620365355186&usg=AFQjCNHe0xlpzCOIVP02E8OyQOwLzec7NA";
		//$url = "http://www.baidu.com";
		$json_obj = $this->wget($url);
		print_r(($json_obj));exit;
		if(empty($_REQUEST['import_type'])){
			$_REQUEST['import_type'] = 'images';
		}
    	//尺寸配置
		$attr = array();
		$attr['z'] = array(
			'0'=>'全部尺寸',
			'1'=>'小尺寸',
			'2'=>'中尺寸',
			'3'=>'大尺寸',
			'9'=>'特大尺寸',
    	    '1024x768'=>'1024x768',
            '1280x800'=>'1280x800',
            '1280x960'=>'1280x960',
            '1280x1024'=>'1280x1024',
            '1440x900'=>'1440x900',
            '1440x900'=>'1440x900',
            '1600x900'=>'1600x900',
            '1600x1200'=>'1600x1200',
            '1680x1050'=>'1680x1050',
            '1920x1080'=>'1920x1080',
            '1920x1200'=>'1920x1200',
            '2560x1600'=>'2560x1600',
		);
		$attr['ic'] = array(
			0=> '全部颜色',
			1=> '红色',
			256=>'橙色',
			2=>'黄色',
			4=>'绿色',
			32=>'紫色',
			64=>'粉色',
			8=>'青色',
			16=>'蓝色',
			128=>'棕色',
			1024=>'白色',
			512=>'黑色',
			2048=>'黑白图片',
		);
		$attr['lm']=array('-1'=>'全部格式','6'=>'动态图片','7'=>'静态图片');
		$attr['s']=array('0'=>'全部图片','1'=>'壁纸','2'=>'表情','3'=>'头像','4'=>'新闻图片');
    	$this->assign('attr', $attr);
		
		if(!empty($_REQUEST['word'])){

		}
        $this->display();
		
		
	}
	
	public function wget($url){
		// sendRequest
		// note how referer is set manually
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$HTTP_HOST = $_SERVER['HTTP_HOST'];//
		curl_setopt($ch, CURLOPT_REFERER, $HTTP_HOST);
		$body = curl_exec($ch);
		$code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //获取返回状态
		curl_close($ch);
		
		// now, process the JSON string
		return $body;
		// now have some fun with the results...		
	}
	function curl_get_data($url,$data=NULL,$is_post = false){
		// 初始化一个 cURL 对象
		$curl = curl_init();
		// 设置你需要抓取的URL
		curl_setopt($curl, CURLOPT_URL, $url);
		// 设置header
		curl_setopt($curl, CURLOPT_HEADER, 0);
		// 设置cURL 参数，要求结果保存到字符串中还是输出到屏幕上。
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		//指定post数据
		if($is_post)curl_setopt($curl, CURLOPT_POST, 1);
		//添加变量
		if($data){
			$data = http_build_query($data);
			curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
		}
		// 运行cURL，请求网页
        curl_setopt($curl, CURLOPT_VERBOSE, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
		$r_data = curl_exec($curl);
		$code = curl_getinfo($curl, CURLINFO_HTTP_CODE); //获取返回状态
		// 关闭URL请求
		curl_close($curl);
		return $r_data;
	}
	
}